#include <iostream>
#include <vector>

using namespace std;

class Solution
{
public:
    int maximumsSplicedArray(vector<int> &nums1, vector<int> &nums2)
    {
        int lastMax = 0, lastMin = 0;
        int maxMax = 0, minMin = 0;
        int sum1 = 0;
        int sum2 = 0;
        for (int i = 0; i < nums1.size(); i++)
        {
            sum1 += nums1[i];
            sum2 += nums2[i];
            nums1[i] = nums2[i] - nums1[i];
            lastMax = max(nums1[i], lastMax + nums1[i]);
            maxMax = max(maxMax, lastMax);
            lastMin = min(nums1[i], lastMin + nums1[i]);
            minMin = min(minMin, lastMin);
        }
        // return max(max(sum1 + maxMax, sum2 - maxMax), max(sum1 + minMin, sum2 - minMin));
        return max(sum1 + maxMax, sum2 - minMin);
    }
};

int main()
{
    cout << "Code2321" << endl;
    Solution s;
    cout << s.maximumsSplicedArray(vector<int>{6, 6, 6}, vector<int>{1, 9, 1});
    // cout << s.maximumsSplicedArray(vector<int>{2, 4, 2, 7, 3}, vector<int>{5, 2, 5, 4, 2});
    return 0;
}